package com.my.aslife.controller;


import com.my.aslife.module.common.Condition;
import com.my.aslife.module.common.ErrorCode;
import com.my.aslife.module.common.PageRequestVo;
import com.my.aslife.module.common.ResponseResult;
import com.my.aslife.module.entity.dtos.OrdersAcceptDto;
import com.my.aslife.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2022-12-12
 */
@RestController
@RequestMapping("/api/my/orders")
@CrossOrigin
@Slf4j
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @GetMapping("/get/list")
    public ResponseResult selectOrderInfoByPageAndCondition(@RequestParam Integer current, @RequestParam Integer pageSize,
                                               @RequestParam(value = "orderId", required = false) String orderId) {

        PageRequestVo pageRequestVo = new PageRequestVo(current, pageSize);

        return ordersService.selectOrderInfoByPageOrCondition(pageRequestVo);
    }

    @PostMapping("/query/{orderId}")
    public ResponseResult queryOrderByOrderId(@PathVariable Long orderId){
        return ordersService.queryOrderByOrderId(orderId);
    }

    @PostMapping("/accept/demand")
    public ResponseResult acceptDemand(@RequestBody OrdersAcceptDto ordersAcceptDto){
        if (ordersAcceptDto.getDemandKey() == null || ordersAcceptDto.getUid() == null) {
            return ResponseResult.failed(ErrorCode.C_PARAMS_NOT_NULL);
        }
        return ordersService.acceptDemand(ordersAcceptDto);
    }

    @PostMapping("/reminder/{orderId}")
    public ResponseResult reminderToDemand(@PathVariable Long orderId) {

        return ordersService.reminderToDemand(orderId);
    }

    @PostMapping("/finish/demand")
    public ResponseResult uploadFinishDemandUrl(MultipartFile file){
        return ordersService.uploadFinishDemandUrl(file);
    }

    @PostMapping("/transfer/order/{orderId}")
    public ResponseResult transferOrder(@PathVariable Long orderId){
        return ordersService.transferOrder(orderId);
    }

}
